const {mysql} = require('../../qcloud')

async function userInfo(ctx) {
  const {user_id,user_name,user_head} = ctx.request.body
  const oldData = await mysql('user_info').where({
    'user_id':user_id
  }).select()
  if(oldData.length>0){
    ctx.state={
      data:"cunzai"
    }
  }
  else{
    const data = await mysql('user_info').insert({
      'user_id': user_id,
      'user_name':user_name,
      'user_head':user_head
    })
    if (data) {
      ctx.state = {
        data: "ok"
      }
    } else {
      ctx.state = {
        data: "false"
      }
    }
  }
}

async function getId(ctx) {
  const user_id =ctx.query.user_id
  console.log("user_id========",user_id)
  const info = await mysql('user_info').where({
    'user_id':user_id
  }).select()
   ctx.state.data= {
      info
  }
}

module.exports = {
  userInfo,
  getId
}